﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Happy.ExtentionMethods;

namespace Happy.Domain.EntityFramework
{
    /// <summary>
    /// 工作单元拦截器基类。
    /// </summary>
    public abstract class Interceptor<TUnitOfWork> : IInterceptor
        where TUnitOfWork : UnitOfWork
    {
        /// <inheritdoc />
        public void BeforeFlush(UnitOfWork unitOfWork)
        {
            unitOfWork.MustNotNull("unitOfWork");

            this.BeforeFlush(unitOfWork as TUnitOfWork);
        }

        /// <inheritdoc />
        public void AfterFlush(UnitOfWork unitOfWork)
        {
            unitOfWork.MustNotNull("unitOfWork");

            this.AfterFlush(unitOfWork as TUnitOfWork);
        }

        /// <summary>
        /// 提交前的拦截点。
        /// </summary>
        protected virtual void BeforeFlush(TUnitOfWork unitOfWork) { }

        /// <summary>
        /// 提交后的拦截点。
        /// </summary>
        protected virtual void AfterFlush(TUnitOfWork unitOfWork) { }
    }
}
